<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title></title>
</head>
<body>

<!--页面内容开始-->
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox ">
                <div class="ibox-title">
                    <h5>会员等级规则
会员升降级的依据列表 </h5>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <div class="m-l-xs toolbar">
                            <button class="btn btn-sm btn-primary" type="button"
                                    onclick="memberlevelruleListObj.addOrUpdateHandle()"><i
                                    class="fa fa-plus"></i>&nbsp;新增
                            </button>
                            <button id="memberlevelruleList_delAll" class="btn btn-sm btn-danger" type="button"
                                    disabled="disabled"
                                    onclick="memberlevelruleListObj.deleteHandle()"><i
                                    class="fa fa-trash"></i>&nbsp;批量删除
                            </button>
                        </div>
                        <table id="memberlevelruleList_table" class="table table-striped"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!--页面内容结束-->
<div th:replace="web/member/memberlevelrule-add-or-update::memberlevelruleAddOrUpdate"></div>
<script type="text/javascript">
    $().ready(function () {
         memberlevelruleListObj.initTable();
    })
    var memberlevelruleListObj = new Object({
        dataListSelections: [],
        myTable: $('#memberlevelruleList_table'),
        addOrUpdateHandle: function (id) {
            memberlevelruleAddOrUpdateObj.init(id);
        },
        deleteHandle: function (id) {
            let ids = id ? [id] :
                    this.dataListSelections.map(item => {
                        return item.id;
                    });
            let tipMsg = id ? '删除' : '批量删除';
            $.mySwalConfirm(`将${tipMsg}，确认吗？`, function () {
                $.myPost({
                    url: `/member/memberlevelrule/delete`,
                    dataType: "json",
                    data: ids,
                    success: function (data) {
                        if (data && data.code === 0) {
                            toastr.success(data.msg, '操作提示')
                            memberlevelruleListObj.refreshDataList();
                        } else {
                            toastr.error(data.msg, '操作失败')
                        }
                    }
                })
            });
        },
        checkRowHander: function () {
            memberlevelruleListObj.dataListSelections = memberlevelruleListObj.myTable.bootstrapTable('getSelections');
            if (memberlevelruleListObj.dataListSelections.length > 0) {
                $('#memberlevelruleList_delAll').removeAttr("disabled");
            } else {
                $('#memberlevelruleList_delAll').attr("disabled", "disabled");
            }
        },
        refreshDataList: function () {
            memberlevelruleListObj.myTable.bootstrapTable('refresh');
        },
        initTable: function () {
            memberlevelruleListObj.myTable.bootstrapTable({
                toolbar: ".toolbar",
                search: true,
                trimOnSearch: true,
                pagination: true,
                sidePagination: 'server',
                url: '/member/memberlevelrule/list',
                formatNoMatches: function () {  //没有匹配的结果
                    return '暂无数据';
                },
                queryParams: function (param) {
                    return param;
                },
                onCheck: function (row, $element) {
                    memberlevelruleListObj.checkRowHander();
                },
                onUncheck: function (row, $element) {
                    memberlevelruleListObj.checkRowHander();
                },
                onCheckAll: function (row, $element) {
                    memberlevelruleListObj.checkRowHander();
                },
                onUncheckAll: function (row, $element) {
                    memberlevelruleListObj.checkRowHander();
                },
                onCheckSome: function (row) {
                    memberlevelruleListObj.checkRowHander();
                },
                onUncheckSome: function (row) {
                    memberlevelruleListObj.checkRowHander();
                },
                columns: [{
                    title: '#',
                    align: 'center',
                    width: 50,
                    checkbox: true,
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                                            {
                            title: 'ID',
                            field: 'id'
                        },
                                            {
                            title: '版本',
                            field: 'version'
                        },
                                            {
                            title: '排序',
                            field: 'sort'
                        },
                                            {
                            title: '创建人',
                            field: 'createUser'
                        },
                                            {
                            title: '创建时间',
                            field: 'createTime'
                        },
                                            {
                            title: '更新人',
                            field: 'updateUser'
                        },
                                            {
                            title: '更新时间',
                            field: 'updateTime'
                        },
                                            {
                            title: '备注',
                            field: 'remark'
                        },
                                            {
                            title: '删除标识',
                            field: 'deleted'
                        },
                                            {
                            title: '等级信息ID',
                            field: 'levelId'
                        },
                                            {
                            title: '规则类型
            使用哪种方式来计量
            001- 指标
            002- 团队',
                            field: 'ruleType'
                        },
                                            {
                            title: '指标类型
            使用指标（规则类型=001）来计量的规则中，再进行分类
            001- 总指标值需要大于等于的值
            002- 某个单项指标值需要大于等于的值
            ',
                            field: 'indexType'
                        },
                                            {
                            title: '应用ID
            使用指标（规则类型=001）来计量的规则中，对应的应用ID',
                            field: 'indexId'
                        },
                                            {
                            title: '运算标识
            ge- 大于等于
            gt- 大于
            le- 小于等于
            lt- 小于
            ',
                            field: 'ruleOper'
                        },
                                            {
                            title: '规则值',
                            field: 'ruleValue'
                        },
                                            {
                            title: '',
                            field: 'ruleEnable'
                        },
                                        {
                        title: '操作',
                        align: 'center',
                        width: 100,
                        events: {
                            'click .edit': function (e, value, row, index) {
                                    memberlevelruleListObj.addOrUpdateHandle(row.id)
                            },
                            'click .trash': function (e, value, row, index) {
                                    memberlevelruleListObj.deleteHandle(row.id)
                            }
                        },
                        formatter: function (value, row, index) {
                            var opers = [];
                            opers.push(`<a class="edit btn btn-white btn-bitbucket text-success" title="编辑">
                                    <i class="fa fa-edit"></i>
                                </a>`)
                            opers.push(`<a class="trash btn btn-white btn-bitbucket text-info" title="删除">
                                    <i class="fa fa-trash"></i>
                                </a>`)
                            return opers.join('');
                        }
                    }],
                responseHandler: function (res) {
                    return {
                        total: res.page.totalCount,
                        rows: res.page.list
                    };
                }
            });
        }
    })
</script>
</body>
</html>